﻿using Centa.Agency.Application.Entity;
using Centa.Agency.Repository.Interface;
using Service.EntityFrameWork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Centa.Agency.Repository.Service
{
    public class UserInfoRepository : IUserInfoRepository
    {
        DemoDbContext _dbContext;
        public UserInfoRepository(DemoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public int AddUserInfo(UserInfo entity)
        {
            _dbContext.Add(entity);
            return _dbContext.SaveChanges(); ;
        }

        public int DelUserInfo(UserInfo entity)
        {
            _dbContext.Remove(entity);
            return _dbContext.SaveChanges();
        }

        public int DelUserInfo(int id)
        {
            var entity = GetUserInfos().FirstOrDefault(m => m.Id == id);
            return DelUserInfo(entity);
        }

        public int EditeUserInfo(UserInfo entity)
        {
            _dbContext.Update(entity);

            return _dbContext.SaveChanges();
        }

        public IEnumerable<UserInfo> GetUserInfoData()
        {
            return GetUserInfos().ToList();
        }

        public IQueryable<UserInfo> GetUserInfos()
        {
            Expression<Func<UserInfo, bool>> filter = (a =>true);        
            var data = _dbContext.UserInfoDbSet.Where(filter);
            return data;
        }
    }
}
